<template>
	<view>
		<view class="cu-modal bottom-modal" v-if="type==1" :class="isShow?'show':''" @click="noModal">
			<view class="cu-dialog " @click.stop="">
				<view class="cu-bar justify-end" v-if="title">
					<view class="content">{{title}}</view>
					<view class="action" @click="noModal">
						<text class="text-red"></text>
					</view>
				</view>
				<view class="modal-content">
					<slot name="content"></slot>
				</view>
				<view class="border-top footSubBtnList" v-if="btn">
					<button class="bg-green" @click="noModal()">{{btn[0]}}</button>
					<button class="bg-red" @click="yesModal(1)">{{btn[1]}}</button>
					<button v-if="btn[2]" class="bg-blue" @click="yesModal(2)">{{btn[2]}}</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'cu-modal',
		props: {
			type: {
				type: Number,
				default: 1,
			},
			id: {
				type: String,
				default: '',
			},
			title: {
				type: String,
				default: '衣里辅料',
			},
			show: {
				type: [String, Boolean],
				default: false,
			},
			btn: {
				type: Array,
				default: () => ['取消', '确定']
			}
		},
		data() {
			return {

			}
		},
		model: {
			prop: 'show',
			event: 'returnBack'
		},
		computed: {
			isShow() {
				let {show,id} = this
				if (typeof(show) == 'string' && id) {
					return (id && id == show)
				} else {
					return this.show
				}
			}
		},
		methods: {
			yesModal(i) {
				if (i == 1) {
					this.$emit('yes')
				} else {
					this.$emit('ok')
				}
			},
			noModal() {
				// this.show = false
				this.$emit('returnBack', false);
				console.log(this.show)
			},
		},
	}
</script>

<style lang="less">
	.footSubBtnList {
		height: 140upx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		button {
			border-radius: 5000px;
			height: 88upx;
			margin: 0 20upx;
			color: #fff;
			font-size: 32upx;
			flex: 1;
			text-align: center;
			line-height: 88upx;
		}
	}

	.border-top {
		border-top: 1px solid #ddd;
	}

	.justify-end {
		justify-content: flex-end;
	}

	.cu-bar {
		display: flex;
		position: relative;
		align-items: center;
		min-height: 100upx;
		justify-content: space-between;
		border-bottom: 1px solid #ddd;
	}

	.cu-bar .action {
		display: flex;
		align-items: center;
		height: 100%;
		justify-content: center;
		max-width: 100%;
	}

	.cu-bar .content {
		position: absolute;
		text-align: center;
		width: calc(100% - 340upx);
		left: 0;
		right: 0;
		bottom: 0;
		top: 0;
		margin: auto;
		height: 60upx;
		font-size: 32upx;
		line-height: 60upx;
		cursor: none;
		pointer-events: none;
		text-overflow: ellipsis;
		white-space: nowrap;
		overflow: hidden;
	}

	.modal-content {
		text-align: center;
		min-height: 600upx;
		max-height: 80vh;
		overflow-y: scroll;
	}
</style>
